#ifndef ROPropertyUpdater_H
#define ROPropertyUpdater_H

#include <QObject>
#include <QtQmlIntegration>

class ROSyncProperty;
//属性同步器，用于控制共享属性的同步机制
class ROPropertyUpdater:public QObject
{
    Q_OBJECT
    QML_ELEMENT
public:
    enum class SafePolicy//属性更新的安全性策略
    {
        Safe,//使用更安全的更新方式，底层是tcp
        Fast//使用更快捷的更新方式，底层是udp
    };
    Q_ENUM(SafePolicy)

public:
    ROPropertyUpdater(QObject* parent = nullptr);

    SafePolicy safePolicy() const;
    void setSafePolicy(SafePolicy newSafePolicy);

    bool enabled() const;
    void setEnabled(bool newEnabled);

protected:
    void updateProperty(ROSyncProperty* target,const QStringList& props);

signals:
    void safePolicyChanged();

    void enabledChanged();

private:
    virtual QObject* registerUpdater(ROSyncProperty* source) = 0;

private:
    SafePolicy m_safePolicy;
    bool m_enabled = true;
    friend class ROSyncProperty;
    Q_PROPERTY(SafePolicy safePolicy READ safePolicy WRITE setSafePolicy NOTIFY safePolicyChanged FINAL)
    Q_PROPERTY(bool enabled READ enabled WRITE setEnabled NOTIFY enabledChanged FINAL)
};

#endif
